home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / bit / src / ulib / ulib.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  8KB  |  297 lines

  1. /*
  2.  * $Id: ulib.h,v 0.80 1994/02/24 09:48:11 zhao Exp $
  3.  *
  4.  *.  Copyright(c) 1993,1994 by T.C. Zhao
  5.  *   All rights reserved.
  6.  *.
  7.  *    Macros and Prototypes for the utilities routines
  8.  */
  9.  
  10. #ifndef TC_ULIB_H
  11. #define TC_ULIB_H
  12.  
  13. #include <stdio.h>        /* for FILE */
  14. #include <time.h>        /* time_t */
  15.  
  16. extern int sginap(long);    /* never decleared in system headers */
  17.  
  18. /* For lint: _semputc and _semgetc never decleared in stdio.h */
  19. #ifdef lint
  20.  
  21. extern int _semputc(int, FILE *);
  22. extern int _semgetc(FILE *);
  23. extern const int ZERO;
  24.  
  25. #else /* !defined lint */
  26.  
  27. #ifdef ZERO
  28. #undef ZERO
  29. #endif /* def ZERO */
  30.  
  31. #define ZERO 0
  32. #endif /* lint related */
  33.  
  34. /********** Point routine  **********************/
  35. typedef struct
  36.   {
  37.       int x, y;
  38.   }
  39. Point_t;
  40.  
  41. /********** Rectangle routines ******************/
  42. typedef struct
  43.   {
  44.       int x, y;
  45.       int w, h;
  46.   }
  47. Rect_t;
  48.  
  49. extern const Rect_t *make_rect(int, int, int, int);
  50. extern const Rect_t *union_rect(const Rect_t *, const Rect_t *);
  51. extern const Rect_t *sum_rect(const Rect_t *, const Rect_t *);
  52. extern Rect_t *canonicalize_rect(Rect_t *);
  53. extern void shift_rect(Rect_t *, int, int);
  54. extern void inc_rect(Rect_t *, int, int);
  55. extern void set_rect(Rect_t *, int, int, int, int);
  56. extern int inside_rect(int, int, const Rect_t *);
  57. extern int equal_rect(const Rect_t *, const Rect_t *);
  58. extern int cover_rect(const Rect_t *, const Rect_t *);
  59. extern Rect_t *copy_rect(Rect_t *, const Rect_t *);
  60.  
  61. /**** for compilation with GCC on ultrix *******/
  62.  
  63. extern char *strdup(const char *);
  64. extern int strcasecmp(const char *, const char *);
  65. extern char *getenv(const char *);
  66.  
  67. /****************************************************************
  68.  * Semi-portable directory reader with cache
  69.  ******************************************************************/
  70. #include <limits.h>
  71.  
  72. #ifndef PATH_MAX
  73. #define PATH_MAX 1024
  74. #endif
  75.  
  76. enum
  77.   {
  78.       FT_DIR, FT_FILE, FT_OTHER
  79.   };
  80.  
  81. typedef struct
  82.   {
  83.       char *name;        /* entry name                 */
  84.       short type;        /* one of the enums           */
  85.   }
  86. Dirlist;
  87.  
  88. extern void free_all_dirlist(void);
  89. extern Dirlist *get_dir_list(const char *, const char *, int *, int);
  90. extern void rm_all_files(const char *, const char *);
  91. extern unsigned long f_mtime(const char *);
  92.  
  93. /*********** Portable IO operations ***********/
  94.  
  95. extern int get2LSBF(FILE *);
  96. extern int get2MSBF(FILE *);
  97. extern long get4LSBF(FILE *);
  98. extern long get4MSBF(FILE *);
  99.  
  100. extern void put2LSBF(int, FILE *);
  101. extern void put2MSBF(int, FILE *);
  102. extern void put4LSBF(long, FILE *);
  103. extern void put4MSBF(long, FILE *);
  104.  
  105. extern int readint(FILE *);
  106. extern int readpint(FILE *);
  107. extern int readhexint(FILE *);
  108. extern int readstring(FILE *, char[], int);
  109. extern int readline(FILE *, char[], int);
  110. extern double readfloat(FILE *);
  111. extern double readpfloat(FILE *);
  112. extern void set_read_silent(int);
  113. extern int skip_comment(FILE *);
  114.  
  115. /************ Some string utilities ****************/
  116.  
  117. extern char *de_space(char *);
  118. extern char *space_de(char *);
  119. extern char *de_space_de(char *);
  120.  
  121.  
  122. /********** A recursive descent parar/evaluator *******/
  123.  
  124. extern int rd_evaluate(const char *, float *, float *, int);
  125.  
  126.  
  127. /******************************************************************
  128.  * convert number to string with limited capability, primarily
  129.  * for speed critical situations, like continuous reporting etc
  130.  ******************************************************************/
  131.  
  132. extern const char *itoa(int);
  133. extern const char *ftoa(float, int);
  134. extern unsigned int power_of_2(unsigned int);
  135.  
  136. /********* Interpolation *************************************/
  137.  
  138. extern int lp_interpol(float *, float *, int, float,
  139.                float *, float *, int *, int);
  140.  
  141. extern float val_lp_interpol(float *, float *, int, float, int);
  142.  
  143. /********* Variable number arguments strcat ******************/
  144.  
  145. extern char *vstrcat(const char *,...);
  146. extern void free_vstrcat(void *);
  147.  
  148. extern int sep_choices(char *, char *[]);
  149. extern void set_sep_letter(int);
  150. extern const char *comb_choices(char *[], int);
  151.  
  152. /********** Save and restore "current directory" *************/
  153.  
  154. extern void push_dir(void);
  155. extern void pop_dir(void);
  156.  
  157. /****** UNIX specific utilities ********/
  158.  
  159. extern unsigned msleep(unsigned);
  160. extern unsigned malarm(unsigned);
  161. extern int split_fname(char[], char[], const char *);
  162. extern char *fix_dirname(char[]);
  163. extern char *fix_dir_tail(char[]);
  164. extern const char *contract_dirname(const char *, int);
  165. extern int is_valid_dir(const char *);
  166.  
  167. extern const char *file_ext(const char *);
  168. extern const char *file_tail(const char *);
  169.  
  170. extern char *get_tmpf(const char *);
  171. extern void del_tmpf(char *);
  172. extern void del_all_tmpf(void);
  173.  
  174. /******** Timing routines *******************/
  175.  
  176. extern double current_time(void);
  177. extern void reset_time(void);
  178. extern long time_passed(void);
  179. extern const char *current_ascii_date(void);
  180. extern time_t date_to_time(const char *);
  181.  
  182. /******** misc. utilities **************/
  183. extern int b_search(float *, int, float);
  184. extern void find_bbox(int, int, int, int, float, int *, int *, int *, int *);
  185. extern Rect_t *spoly_bounds(short *, short *, int);
  186.  
  187. /******** pattern matching (after Rich Salz) ************/
  188. extern int wildmat(const char *, const char *);
  189.  
  190.  
  191. /************  misc. macros ***********************/
  192.  
  193. #ifndef Badfread
  194. #define Badfread(buf, es, n, fp)    (fread(buf, es, n, fp) != n)
  195. #define Badfwrite(buf, es, n, fp)   (fwrite(buf, es, n, fp) != n)
  196. #define Badfgets(buf, l, fp)        (fgets(buf, l, fp) == 0)
  197. #endif
  198.  
  199. #ifndef Abs
  200. #define Abs(a)      ((a) >= 0 ? (a) : -(a))
  201. #endif
  202.  
  203. #ifndef Min
  204. #define Min(a, b)   ( ((a) > (b)) ? (b) : (a))
  205. #endif
  206.  
  207. #ifndef Max
  208. #define Max(a, b)   ( ((a) > (b)) ? (a) : (b))
  209. #endif
  210.  
  211. #ifndef StrReDup
  212. #define StrReDup(a, b)  do { if(a) free(a); a = strdup(b); } while(ZERO)
  213. #endif
  214.  
  215. #ifndef Readline
  216. #define Readline(s, fp)                                         \
  217.     do                                                      \
  218.     {   register int c_;                                    \
  219.         while ((c_ = getc(fp)) != EOF && c_ != '\n')        \
  220.            *s++ = c_;                                       \
  221.             *s = '\0';                                          \
  222.          } while (ZERO)
  223. #endif
  224.  
  225. /*********************************************************************
  226.  * Basic error handling routines
  227.  ********************************************************************/
  228.  
  229. #ifndef TC_ERROR_H
  230. #define TC_ERROR_H
  231.  
  232. #include <errno.h>
  233.  
  234. /*
  235.  * message levels(verbosity). Error generating routine should
  236.  * have a (positive) control parameter specifying how loud
  237.  * to bark (i.e., amount of messages generated)
  238.  */
  239. typedef enum
  240.   {
  241.       ML_ERR = -1,        /* always print       */
  242.       ML_WARN,            /* warning            */
  243.       ML_INFO,            /* good to have       */
  244.       ML_DEBUG,            /* many output        */
  245.       ML_TRACE            /* bad program!       */
  246.   } ML_t;
  247.  
  248. /*
  249.  * actions to take when something is not right.
  250.  * A_WAIT = 0, so that a default action is to wait. Not implemented
  251.  */
  252. typedef enum
  253.   {
  254.       A_WAIT,            /* print msg, demanding a response */
  255.       A_MSG,            /* print msg, do nothing           */
  256.       A_QUIT,            /* fatal, quit gracefully          */
  257.       A_DIE            /* fatal, quit immdediately        */
  258.   } Act_t;
  259.  
  260. typedef void (*ErrFunc_) (const char *, const char *,...);
  261. extern ErrFunc_ whereError(int, ML_t, const char *, int), efp_;
  262.  
  263. /*
  264.  * define the actual names that will be used
  265.  */
  266.  
  267. /* no graphics stuff */
  268. #define M_err       (efp_ = whereError(0, ML_ERR, __FILE__, __LINE__))
  269. #define M_warn      (efp_ = whereError(0, ML_WARN, __FILE__, __LINE__))
  270. #define M_info      (efp_ = whereError(0, ML_INFO, __FILE__, __LINE__))
  271. #define M_debug     (efp_ = whereError(0, ML_DEBUG, __FILE__, __LINE__))
  272. #define M_trace     (efp_ = whereError(0, ML_TRACE, __FILE__, __LINE__))
  273. #define M_msg(a, b, c) (efp_=whereError(0, a, b, c))
  274.  
  275. /* graphics    */
  276. #define Bark                (efp_= whereError(1, 0, __FILE__, __LINE__))
  277. #define GM_msg(a, b, c)     (efp_= whereError(1, a, b, c))
  278.  
  279. /*
  280.  * the actual output routines takes three constant strings and an integer
  281.  * in the order title, where, why, 0
  282.  */
  283. typedef void (*Gmsgout_) (const char *, const char *, const char *, int);
  284.  
  285. /****** Misc. control routines **********/
  286. extern void set_err_msg_func(Gmsgout_);
  287. extern void set_err_msg_fp(FILE *);
  288. extern void set_msg_threshold(ML_t);
  289. extern void set_err_msg_brief(int);
  290.  
  291. #define to_be_written(a) Bark(a,"To be written");
  292.  
  293. #endif /* ERROR_H */
  294.  
  295.  
  296. #endif /* TC_ULIB_H */
  297.